package org.genntii.smcommentlike.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.genntii.smdomain.entity.CommentLike;

@Mapper
public interface CommentLikeMapper extends BaseMapper<CommentLike> {

    @Select("select * from Comment_Like where user_id = #{userId} and comment_id = #{commentId}")
    CommentLike getCommentLiked(@Param("userId")Long userId, @Param("commentId")Long commentId);

    @Select("SELECT count(*) from Comment_Like where `like` = 1 and comment_id = #{commentId}")
    Integer getLike(@Param("commentId")Long commentId);

    @Select("SELECT count(*) from Comment_Like where `like` = 0 and comment_id = #{commentId}")
    Integer getDislike(@Param("commentId")Long commentId);

    @Select("select `like` from Comment_Like where user_id = #{userId} and comment_id = #{commentId}")
    Byte commentLikeExists(@Param("userId")Long userId, @Param("commentId")Long commentId);

    @Delete("delete from Comment_Like where comment_id = #{commentId} and user_id = #{userId}")
    void delCommentLike(@Param("commentId")Long commentId, @Param("userId")Long userId);

}
